package metier.client;

import java.rmi.AccessException;
import java.rmi.NotBoundException;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.HashMap;

public class MetierFactory {
	public static MetierFactory instance;

	private Registry registry;

	public static MetierFactory getInstance() {
		if (MetierFactory.instance == null) {
			MetierFactory.instance = new MetierFactory();
		}
		return MetierFactory.instance;
	}

	private MetierFactory() {
		try {
			// récupère la registry créée par le serveur metier
			registry = LocateRegistry.getRegistry(2000);
			
			// créer la connexion à la base
			
			
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public Remote getMetier(String name) {
		Remote metier = null;
		try {
			// TODO : ne pas mettre l'url en dur
			metier = registry.lookup("rmi://localhost:2000/" + name);

		} catch (AccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (NotBoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return metier;
	}

}
